<template>
	<view class="page" v-if="!loadding" :style="{minHeight:windowHeight+'px'}">
		<view class="top-head">
			<view class="head-l">
				<image src="../../../../static/app/jiaotou1.png" @click="gotoDetail()" mode=""></image>
			</view>
			<view class="head-title">安排车辆</view>
			<view class="head-r" @click="gotoPage('/pages/user/orderRecord/orderAddCar/orderAddCar')">+ 添加车辆</view>
		</view>

		<view class="car-wrap">
			<view class="car-list">


				<view class="car-item" v-for="(item,index) of car" :key="index" v-if="item.status == 1">
					<view class="car-pic">
						<image :src="item.car_info4" mode=""></image>
						<!-- <image src="../../../static/app/logo.png" mode=""></image> -->
					</view>
					<view class="car-info">
						<view class="car-item-head">
							<view>{{item.type_name}}</view>

							<!-- <view>小型客车</view> -->
							<!-- <text v-if="item.status == -1" >已注销</text>
							<text v-if="item.status == 0" >审核中</text>
							<text v-if="item.status == 1" >已审核</text> -->
						</view>
						<!-- <view class="car-number">桂C 123456</view> -->
						<view class="car-number">{{item.car_number}}</view>
						<view class="car-item-bottom">
							<text>司机：{{item.drivername}}</text>
							<!-- <image src="../../../../static/app/jiaotou.png" mode=""></image> -->
						</view>
					</view>
					<view class="info_tick" @click="selectCar(item)">
						<image v-show="car_id == item.car_id" src="../../../../static/tick1.png"></image>
					</view>
					<view class="sure" @click="formData">
						确定
					</view>
				</view>
			</view>
		</view>
		
		<!-- 没有记录 -->
		<view class="d-c-c p30" v-if="car.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<!-- <uni-load-more v-else :loadingType="loadingType"></uni-load-more> -->
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadding: false,
				car: '',
				car_id: [],
				/*可滚动视图区域高度*/
				windowHeight: 0,
				order_id:'',//订单id
				type:'',//订单类型
			};
		},
		onShow() {
			/*获取数据*/
			this.getData();
		},
		onLoad(e) {
			//console.log(e.id);
			if(e.select == 1){
				this.order_id=e.id;
				//this.type = e.type;
				//this.car_id=e.car_id;
			}
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
					console.log(this.windowHeight);
				}
			});
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.car.length != 0 && this.no_more) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		methods: {
			gotoDetail(){
				uni.navigateTo({
					url:'/pages/user/orderRecord/orderDetail/orderDetail?select=2&id='+this.order_id
				})
			},
			/*返回安排的车辆*/
			formData() {
				let self = this;
				if(self.car_id == ''){
					uni.showToast({
						title:'请选择车辆',
						duration:2000,
						icon:'none'
					});
					return;
				}
				let id = [];
				id.push({car_id:self.car_id})
				 // id.car_id = self.car_id
				 let id2 = ''
				 id2 = JSON.stringify(id)
				 console.log(id2)
				// return;
				uni.showLoading({
					title: '加载中'
				});
				self._post('order.CarOrder/plan_car', 
				{
					car_id:id2,
					order_id:self.order_id
				},
				 function(res) {
					//self.car = res.data.car;
					//console.log("111");
					console.log(res);
					uni.navigateTo({
						url: '/pages/user/orderRecord/detail/detail?select=2&&id=' + self.order_id+'&&type='+self.type,
					});
					uni.hideLoading();
				});
			},
			/* 提交 */
			// formData() {
			// 	console.log(this.car_id)
			// 	console.log(this.order_id);
			// 	console.log(this.type);
			// 	uni.navigateTo({
			// 		url: '/pages/user/orderRecord/detail/detail?select=2&&id=' + this.order_id+'&&type='+this.type,
			// 	});
			// },
			/* 选择司机 */
			selectCar(item) {
				//console.log(item)
				this.car_id = item.car_id;
				//console.log(this.car_id);
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('user.index/my_car', {}, function(res) {
					self.car = res.data.car;
					//console.log("111");
					//console.log(res);
					// self.loadding = false;
					uni.hideLoading();
				});
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path
					});
				} else {
					self[path]();
				}
			},
		}
	}
</script>

<style lang="scss">
	@import 'arrange_car.scss';
</style>
